package com.zwz.control;

import com.zwz.bean.RootLoginInfo;
import com.zwz.control.util.R;
import com.zwz.service.RootLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/root")
public class RootLoginController {


    @Autowired
    private RootLoginService rootLoginService;

    /**
     * 系统管理员登录
     *  只提供登录功能
     * @param rootLoginInfo 参数封装
     * @return Result
     */
    @PostMapping(value = "/login")
    public R login(@RequestBody RootLoginInfo rootLoginInfo) {
        Integer userId = rootLoginService.login(rootLoginInfo);
        if (userId == null) {
            return new R(false, "用户名或密码错误");
        } else {
            rootLoginInfo.setId(userId);
            return new R(true, rootLoginInfo, "登录成功");
        }
    }
}
